package com.bdqn.dao;

import java.sql.*;

public class upDateDao {
    public static void main(String[] args) {
        Connection con=null;
        ResultSet rs=null;
        PreparedStatement pstmt=null;
        //第一步加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //获取连接对象
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/school?serverTimezone=GMT-8", "root", "123");
            //写SQL语句
            String sql = "UPDATE student SET studentname=?,phone=? WHERE studentno=5";
            //执行SQL
            pstmt = con.prepareStatement(sql);
            pstmt.setObject(1,"yangjinzhong");
            pstmt.setObject(2,"123450000000");

            int count= pstmt.executeUpdate();
            //处理结果集
            if (count > 0) {
                System.out.println("修改成功");

            }else {
                System.out.println("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (rs!=null){
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (pstmt!=null){
                try {
                    pstmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (con!=null){
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
